package net.homelinux.chaoswg.io.renga.core.gui.operations.visualisations;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import org.jdom.Element;

public class NamedBlockVisualisation extends BlockVisualisation {
    private String name = "";
    
    public NamedBlockVisualisation () {
        super (0,0,64,64);
        this.inner = Color.WHITE;
    }
    
    public NamedBlockVisualisation (final String name) {
        super (0,0,64,64);
        this.name = name;
        this.inner = Color.WHITE;
    }

    public NamedBlockVisualisation (final int x, final int y, final int width, final int heigth, final String name) {
        super (x,y,width,heigth);
        this.name = name;
        this.inner = Color.WHITE;
    }
    
    public NamedBlockVisualisation (final Point position, final int width, final int height, final String name) {
        super (position, width, height);
        this.name = name;
        this.inner = Color.WHITE;
    }

    public NamedBlockVisualisation (final Rectangle rect, final String name) {
        super (rect);
        this.name = name;
        this.inner = Color.WHITE;
    }
    
    @Override
    public void draw(final Graphics g) {
        super.draw(g);
        g.setColor(Color.BLACK);
        g.drawString (name , this.area.x + this.area.width / 2 - g.getFontMetrics().stringWidth(name) / 2 + 2, this.area.y + (this.area.height / 2) + g.getFont().getSize() / 2 - 2);
    }
    
    public void setName (final String name) {
        this.name = name != null ? name : "";
    }
    
    public Element writeYourself() {
        Element e = super.writeYourself();
        Element text = new Element ("name");
        text.setText(name);
        e.addContent (text);
        return e;
    }

}
